﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.loading.loaders {
    import flash.events.*;
    import flash.net.*;
    import net.wooga.pets.events.*;
    import com.adobe.serialization.json.*;
    import net.wooga.pets.constants.*;
    import flash.errors.*;

    public class JSONLoader extends AbstractLoader {

        private var _loader:URLLoader;

        public function JSONLoader(){
            this._loader = new URLLoader();
            super();
        }
        override public function start():void{
            super.start();
            var request:URLRequest = getRequest(path);
            try {
                this._loader.load(request);
            } catch(error:IOError) {
                l(("could not load " + path));
                dispatcher.dispatchEvent(new InfoEvent(EventConstants.REPORT_PROBLEM, null, ("could not load " + path)));
            };
        }
        override protected function get data(){
            if (this._loader.data){
                try {
                    return (JSON.decode(this._loader.data));
                } catch(error:JSONParseError) {
                    l(("could not parse json " + path));
                    dispatcher.dispatchEvent(new InfoEvent(EventConstants.REPORT_PROBLEM, null, ("could not parse json " + path)));
                };
            };
            return ({});
        }
        override protected function get dispatcher():IEventDispatcher{
            return (this._loader);
        }
        override protected function handleLoadedData():void{
            var _local1:int;
            super.handleLoadedData();
            if (((((_result.data) && (!((_result.data == "ok"))))) && (_result.data.status))){
                _local1 = int(_result.data.status);
                if (_local1 >= 400){
                    _result.success = false;
                    _result.status = _local1;
                };
            };
        }
        override protected function onError(_arg1:IOErrorEvent):void{
            _result.success = false;
            super.onError(_arg1);
        }

    }
}//package net.wooga.pets.loading.loaders 
